package com.wantupai.translate.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.wantupai.translate.App;
import com.wantupai.translate.utils.ToastUtils;


public class WXEntryActivity extends Activity implements IWXAPIEventHandler {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        App.getWeChatApi().handleIntent(this.getIntent(), this);
    }

    @Override
    public void onReq(BaseReq arg0) {
    }

    @Override
    public void onResp(BaseResp resp) {
        switch (resp.errCode) {
            case BaseResp.ErrCode.ERR_OK:
                if (resp.getType() == 1) {    //1表示登录
                } else if (resp.getType() == 2) {
                    ToastUtils.show("分享成功");
                    // int WXShareType= ShareToThirdPartUtil.mWxShareType;//0是好友，1是朋友圈
                    finish();
                }

                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                //发送取消
                if (resp.getType() == 2) {
                    ToastUtils.show("已取消");
                }
                finish();
                break;
            case BaseResp.ErrCode.ERR_AUTH_DENIED:
                //发送被拒绝
                if (resp.getType() == 2) {
                    ToastUtils.show("分享失败");
                }
                finish();
                break;
            default:
                //发送返回
                finish();
                break;
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        App.getWeChatApi().handleIntent(intent, this);
    }

}